<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - time_this.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2003  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_TIME_THIs_
<font color='#0000FF'>#define</font> DLIB_TIME_THIs_


<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>chrono<font color='#5555FF'>&gt;</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>#define</font> TIME_THIS_TO<font face='Lucida Console'>(</font>_tt_op,_tt_out<font face='Lucida Console'>)</font>                                                                            \
    <b>{</b>                                                                                                           \
        <font color='#0000FF'>auto</font> _tt_start <font color='#5555FF'>=</font> std::chrono::high_resolution_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;                                             \
        <b>{</b>_tt_op;<b>}</b>                                                                                               \
        <font color='#0000FF'>auto</font> _tt_stop <font color='#5555FF'>=</font> std::chrono::high_resolution_clock::<font color='#BB00BB'>now</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;                                              \
        <font color='#0000FF'>auto</font> _tt_thetime <font color='#5555FF'>=</font> _tt_stop<font color='#5555FF'>-</font>_tt_start;                                                                          \
        <font color='#0000FF'>using</font> std::chrono::duration_cast;                                                                       \
        <font color='#0000FF'>using</font> std::chrono::duration;                                                                            \
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_tt_thetime <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> std::chrono::<font color='#BB00BB'>minutes</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>                                                             \
            _tt_out <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\ntime: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> duration_cast<font color='#5555FF'>&lt;</font>duration<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,std::ratio<font color='#5555FF'>&lt;</font><font color='#979000'>60</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>_tt_thetime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>min\n</font>";           \
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_tt_thetime <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> std::chrono::<font color='#BB00BB'>seconds</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>                                                        \
            _tt_out <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\ntime: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> duration_cast<font color='#5555FF'>&lt;</font>duration<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>_tt_thetime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>sec\n</font>";           \
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_tt_thetime <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> std::chrono::<font color='#BB00BB'>milliseconds</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>                                                   \
            _tt_out <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\ntime: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> duration_cast<font color='#5555FF'>&lt;</font>duration<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,std::milli<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>_tt_thetime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>ms\n</font>"; \
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>_tt_thetime <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> std::chrono::<font color='#BB00BB'>microseconds</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>                                                   \
            _tt_out <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\ntime: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> duration_cast<font color='#5555FF'>&lt;</font>duration<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,std::micro<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>_tt_thetime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>us\n</font>"; \
        <font color='#0000FF'>else</font>                                                                                                    \
            _tt_out <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\ntime: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> duration_cast<font color='#5555FF'>&lt;</font>duration<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,std::nano<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>_tt_thetime<font face='Lucida Console'>)</font>.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>ns\n</font>";  \
    <b>}</b>

<font color='#0000FF'>#define</font> TIME_THIS<font face='Lucida Console'>(</font>_tt_op<font face='Lucida Console'>)</font>  TIME_THIS_TO<font face='Lucida Console'>(</font>_tt_op,std::cout<font face='Lucida Console'>)</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_TIME_THIs_
</font>

</pre></body></html>